import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
    state: () => ({
        isLoggedIn: false,
        userName: null,
        nickName: null,
        token: null // 可以根据需要添加其他登录相关信息，如 token 等
    }),
    // 定义getters
    getters: {
        getUserName: (state) => {
            return state.userName;
        },
        getToken: (state) => {
            return state.token;
        }
    },
    actions: {
        login(username, token) {
            this.isLoggedIn = true;
            this.userName = username;
            this.token = token;
        },
        setNickName(nickName) {
            this.nickName = nickName;
        },
        logout() {
            this.isLoggedIn = false;
            this.userName = null;
            this.token = null;
        }
    }
});